﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using HZ.MBSM.DBUtility;
public partial class Supervise_SuperviseUpdate : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        System.Collections.Generic.List<HZ.MBSM.DAL.AccountType> _AccountType = new System.Collections.Generic.List<HZ.MBSM.DAL.AccountType>();
        _AccountType.Add(HZ.MBSM.DAL.AccountType.enumSupervise);
        if (HZ.MBSM.BLL.Login.CheckAssert(_AccountType))
        {
            if (!IsPostBack)
            {
                Int64 AccountId;
                string strSql;
                AccountId = Convert.ToInt64(SysFun.IsSQL(Request.QueryString["AccountId"].ToString()));
                Db db = new Db();
                System.Data.IDataReader dr;
                strSql = "select * from v_Account_AgencyChild where AccountId=" + SysFun.ToTrim(AccountId);
                dr = db.DataReader(strSql);
                while (dr.Read())
                {
                    txtAccountId.Text = SysFun.ToTrim(dr["AccountId"]);
                    txtAccountId.Visible = false;
                    txtAccountName.Text = SysFun.ToTrim(dr["AccountName"]);
                    txtPwd_Bid.Text = SysFun.PasswordDecrypt(SysFun.ToTrim(dr["Pwd_bid"]));
                    txtTelephone.Text = SysFun.ToTrim(dr["Telephone"]);
                    txtUserCode.Text = SysFun.ToTrim(dr["UserCode"]);
                    txtUserName.Text = SysFun.ToTrim(dr["UserName"]);
                    txtZC.Text = SysFun.ToTrim(dr["zc"]);
                    rdoType.SelectedValue = SysFun.ToTrim(dr["Type"]);
                    txtAccountId_father.Text = SysFun.ToTrim(dr["AccountId_father"]);
                    txtAccountId_father.Visible = false;
                    txtIsBid_Landing.Text = SysFun.ToTrim(dr["IsBid_Landing"]);
                    txtIsBid_Landing.Visible = false;
                }
                dr.Close();
                dr.Dispose();
                db.Close();
            }
        }

    }
    protected void BtnSave_Click(object sender, EventArgs e)
    {
        Int64 AccountId_father, AccountId = 0;
        HZ.MBSM.Model.Account _Account = (HZ.MBSM.Model.Account)Session["Account"];
        if (_Account != null)
        {

            AccountId_father = SysFun.ToLong(txtAccountId_father.Text);
            AccountId = SysFun.ToLong(txtAccountId.Text);
            Db db = new Db();
            Grove.ORM.ObjectOperator oo = db.GetObjectOperator();
            Grove.ORM.ObjectOperator oo1 = db.GetObjectOperator();
            HZ.MBSM.Model.AgencyChild AgencyChild = new HZ.MBSM.Model.AgencyChild();
            HZ.MBSM.Model.Account Account = new HZ.MBSM.Model.Account();
            Account.AccountId = AccountId;
            Account.AccountName = SysFun.ToTrim(txtAccountName.Text);
            Account.Pwd_Bid = SysFun.PasswordEncrypt(SysFun.ToTrim(txtPwd_Bid.Text));
            Account.Type = SysFun.ToTrim(rdoType.SelectedValue);
            Account.IsBid_Landing = SysFun.ToTrim(txtIsBid_Landing.Text);
            oo.Update(Account);
            oo.Dispose();
            AgencyChild.AccountId = AccountId;
            AgencyChild.UserCode = SysFun.ToTrim(txtUserCode.Text);
            AgencyChild.AccountId_father = AccountId_father;
            AgencyChild.Telephone = SysFun.ToTrim(txtTelephone.Text);
            AgencyChild.UserName = SysFun.ToTrim(txtUserName.Text);
            AgencyChild.ZC = SysFun.ToTrim(txtZC.Text);
            oo1.Update(AgencyChild);
            oo1.Dispose();
            db.Close();
            //HZ.MBSM.Model.Account _Account = (HZ.MBSM.Model.Account)Session["Account"];
            HZ.MBSM.BLL.LogManage.RecordLoginDetail(_Account.AccountName, Request.UserHostAddress, "更新", "AgencyChild", AgencyChild.AccountId + "|" + AgencyChild.UserName + "|" + AgencyChild.UserCode + "|" + AgencyChild.AccountId_father, "../Agency/RemoteDecComptete.aspx");

        }
        else
        {
            Response.Write("<script language=JavaScript>alert('您还没有登录，暂时无权添加子用户！！！');</script>");
        }
        Response.Write("<script>window.opener.location.reload();window.close();</script>");
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        Response.Write("<script>window.close();</script>");
    }
}
